/*
 * @Author: your name
 * @Date: 2022-02-04 14:12:04
 * @LastEditTime: 2022-02-04 14:55:42
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \ts\09类的get-set.ts
 */

// 私有属性和保护属性不可直接读写，可以通过get 和 set 进行读写
class GetAndSet {
    
    private name:string
    // age简写了，不需要像name定义也可以的
    constructor(name:string, private age:number) {
        this.name = name
    }

    // 获取值
    get getName() {
        // return this.name 
        return this.name +'我可以进行进一步操作呀'
    }

    get getAge() {
        return this.age
    }
    
    // 修改值
    set setName(newName:string) {
        this.name = newName
    }
}

 let getAndSet = new GetAndSet('kele',23)
 console.log(getAndSet.getName)
 console.log(getAndSet.getAge)
 getAndSet.setName = '新名字'
 console.log(getAndSet.getName)
